/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.apt.hanhhanh.matrimony.methods;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import org.apt.matrimony.beans.AccountDetailBeans;
import org.apt.matrimony.beans.SearchAccountBean;
import org.apt.matrimony.db.MyConnection;

/**
 *
 * @author yoko
 */
public class Searchs {

    public static List selectAccountDetails() {
        List<AccountDetailBeans> list = new ArrayList();
        Connection cnn = null;
        PreparedStatement stm = null;
        ResultSet rs = null;
        String sql = "Select * from Account_Details";
        try {
            cnn = MyConnection.openConnection();
            stm = cnn.prepareCall(sql);
            rs = stm.executeQuery();
            while (rs.next()) {
                AccountDetailBeans bean = new AccountDetailBeans();
                bean.setAccount_Details_Id(rs.getInt("Account_Id"));
                list.add(bean);
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            MyConnection.closeConnection(cnn, stm, rs);
        }
        return list;
    }

    public static SearchAccountBean selectAccountDetailbyAccountID(int accountID) {
     SearchAccountBean bean =null;
        Connection cnn = null;
        PreparedStatement stm = null;
        ResultSet rs = null;
        String sql = "SELECT * FROM  Account_Details join Albums on Albums.Album_Id = Account_Details.Album_Id ";
        sql += "  join Album_Types on Albums.Album_Type_Id = Album_Types.Album_Type_Id";
        sql += "  join Images on Images.Image_Id = Albums.Image_Id";
        sql += " WHERE Account_Details.Account_Details_Id = " + accountID;

        try {
            cnn = MyConnection.openConnection();
            stm = cnn.prepareCall(sql);
            rs = stm.executeQuery();
            while (rs.next()) {
                 bean = new SearchAccountBean();
                bean.setFullName("Full_Name");
                bean.setImage_Path("Image_Path");
                bean.setMother_Tongue("Mother_Tongue");
                
                
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            MyConnection.closeConnection(cnn, stm, rs);
        }

        return bean;
    }

//    public static void main(String[] args) {
//        List lst = new ArrayList();
//        lst = Searchs.selectAccountDetailbyAccountID(3);
//    }
}
